export function useTimer(
  handle: () => void,
  timeout: number,
): { startTimer: () => void; stopTimer: () => void } {
  let timer: ReturnType<typeof setInterval> | null = null

  const startTimer = () => {
    if (!timer) {
      timer = setInterval(handle, timeout)
    }
  }

  const stopTimer = () => {
    if (timer) {
      clearInterval(timer)
      timer = null
    }
  }

  return {
    startTimer,
    stopTimer,
  }
}
